package com.link.base.base.trackdisplay.controller;
/**
 * @author: 秦学刚
 * @date: 2018-11-27
 * @comments:
 */

import com.link.base.base.trackdisplay.dao.mybatis.mapper.ReturnServiceMapper;
import com.link.base.base.trackdisplay.model.TrackDisplay;
import com.link.base.base.trackdisplay.service.TrackDisplayService;
import com.link.core.basic.controller.BasicController;
import com.link.core.basic.service.BasicService;
import com.link.core.basic.service.ServiceException;
import com.link.core.basic.service.KeyGenerateService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("/link/trackDisplay")
public class TrackDisplayController extends BasicController<TrackDisplay> {
 
    @Resource
    private KeyGenerateService keyGenerateService;

    @Resource
    private TrackDisplayService trackDisplayService;

    @Resource
    private ReturnServiceMapper returnServiceMapper;


    @Override
    public BasicService<TrackDisplay> getBasicService() throws Exception {
        return trackDisplayService;
    }

    @RequestMapping(value = "/returnService")
    @ResponseBody
    public Map<String, Object> returnService(@RequestBody TrackDisplay entity, HttpSession session,
                                           HttpServletRequest request, HttpServletResponse response) {
        Map<String, Object> result = new HashMap(4);
        try {
            result = trackDisplayService.returnService(entity);
            result.put("success", true);
            result.put("code", "200");
        } catch (ServiceException e) {
            result.put("success", false);
            result.put("message", e.getMessage());
            result.put("detailMessage", e.getMessage());
            result.put("code", e.getCode());
        } catch (Exception e) {
            result.put("success", false);
            result.put("message", e.getMessage());
            result.put("code", "400");
        }
        return result;
    }

    @RequestMapping(value = "/returnMapper")
    @ResponseBody
    public Map<String, Object> returnMapper(@RequestBody TrackDisplay entity, HttpSession session,
                                            HttpServletRequest request, HttpServletResponse response) {
        Map<String, Object> result = new HashMap(4);
        try {
            result = returnServiceMapper.returnService(entity);
            result.put("success", true);
            result.put("code", "200");
        } catch (ServiceException e) {
            result.put("success", false);
            result.put("message", e.getMessage());
            result.put("detailMessage", e.getMessage());
            result.put("code", e.getCode());
        } catch (Exception e) {
            result.put("success", false);
            result.put("message", e.getMessage());
            result.put("code", "400");
        }
        return result;
    }
}
